﻿/*----------------------------------------------------------------
           // Copyright (C) 2008 安华顺通(北京)科技有限公司
           // 版权所有。 
           //
           // 文件名：AppSession.cs
           // 文件功能描述：
           //
           // 
           // 创建标识：丁余良  2008 2008-9-28 16:59:29 
           //
           // 修改标识
           // 修改描述：
           //
           // 修改标识：
           // 修改描述：
----------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.ComponentModel;

namespace RuleCode.Common
{
    public class TypeSession
    {
        public static object GetObjectFromTypeName(string typeName,string[] assemblyNameList)
        { 
            foreach (string assemblyName in assemblyNameList )
            {
                Assembly assembly = Assembly.Load(assemblyName);
                System .Type[] typeList= assembly.GetTypes();
                foreach (System.Type type in typeList )
                {
                    if (type.Name == typeName)
                        return type.GetConstructor(System.Type.EmptyTypes).Invoke(null);
                }
            }
            return null;
        }

        public static object GetObjectFromTypeName(string typeName)
        {
            List<string> assemblyNameList = new List<string>();
            assemblyNameList.AddRange(new string[]{
                                    "System",
                                    "RuleCode.Class"                             
                                    ,"RuleCode.ObjectTree"
                                    ,"RuleCode.WinControl"
                                    ,"RuleCode.Querys"
                                    ,"RuleCode.Table"
                                    ,"System.Data"
                                    ,"System.Windows.Forms"
                                    ,"RuleCode.Common"
                                     });

            return TypeSession.GetObjectFromTypeName(typeName, assemblyNameList.ToArray());
        }
    }
}
